package com.数据结构.排序;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.Arrays;

/**
 * @Date 2021/4/23 16:41
 * @Author WangLinBao
 * @Description
 */
public class InsertSort {
    public static void main(String[] args) {
        int [] arr = new int[]{5,2,6,8,4};
        sort(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.println("arr = " + arr[i]);
        }

    }
    public static void sort(int[] nums){
        int start = 0;
        int end = nums.length-1;
        int size = end -start+1;
        for(int i = start+1;i<size;i++){
            int p=i;
            for(int j = i-1;j>=0;j--){
                if(nums[i]>nums[j]){
                    break;
                }else{
                    p = j;
                }
            }
            int temp = nums[i];
            for(int a = i;a>p;a--){
                nums[a] = nums[a-1];
            }
            nums[p] = temp;
        }
    }
    public static void swap(int[] nums,int left,int right){
        int temp = nums[left];
        nums[left] = nums[right];
        nums[right] = temp;
    }
}
